package midterm.demo3;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.TimerTask;

public class TimeTask extends TimerTask {
    // 高考开始时间
    private LocalDateTime startTime;


    // 构造器，对高考的开始时间进行初始化
    public static void TimeTask() {
        String s = "2026-06-07 09:00:00";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime gk = LocalDateTime.parse(s, formatter);
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime rs = gk.minusSeconds(now.getSecond());//秒
        rs = rs.minusMinutes(now.getMinute());//分
        rs = rs.minusHours(now.getHour());//小时
        rs = rs.minusDays(now.getDayOfYear());//天
        rs = rs.minusYears(now.getYear());

        System.out.println(rs.getYear() + "年" + rs.getDayOfYear() + "天" + rs.getHour() + "时" + rs.getMinute() + "分" + rs.getSecond() + "秒");
























//        int gkm = gk.getAl();
//        System.out.println(gkm);
//        int nowm = gk.getSecond();
//        int m = gkm - nowm;
//        int f = m / 60;
//        m %= 60;
//        int h = f / 60;
//        f %= 60;
//        int day = h / 24;
//        h %= 24;
//        System.out.println(day + "天" + h + "时" + f + "分" + m + "秒");



    }


    // 每一秒执行一次该方法
    @Override
    public void run() {
        // 补全代码：完成倒计时效果
       TimeTask();

    }

}
